package solutions;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-02-06
 * Time: 15:13
 */

//https://leetcode.cn/problems/move-zeroes/submissions/399859723/
class Solution {
    public void moveZeroes(int[] nums) {
        int indexNow = 0;
        int indexNum = 0;
        int m = nums.length;
        while (indexNum < m) {
            if (nums[indexNum] != 0) {
                nums[indexNow++] = nums[indexNum];
            }
            ++indexNum;
        }
        for (int i = indexNow; i < m; i++) {
            nums[i] = 0;
        }
    }
}

//class Solution {
//    public void moveZeroes(int[] nums) {
//        int slow = 0;
//        int fast = 0;
//        for (fast = 0; fast < nums.length; ++fast) {
//            if (nums[fast] != 0) {
//                int temp = nums[slow];
//                nums[slow++] = nums[fast];
//                nums[fast] = temp;
//            }
//        }
//    }
//}
